package alpaca.database;

/**
 * This class is only used to perform JUnit tests.
 *
 */

import java.sql.SQLException;
import java.util.Date;
import java.util.Iterator;

import alpaca.core.Contact;
import alpaca.core.ContactList;
import alpaca.core.IUser;
import alpaca.core.Message;
import alpaca.core.MessageList;
import alpaca.core.ORMLiteUser;
import alpaca.core.UserList;
import alpaca.util.PasswordEncrypter;

public class MockDatabaseSystem implements IDatabaseSystem {
	
	public static final ORMLiteUser MOCK_ACTIVE_USER = new ORMLiteUser("", "", "kalle@mail.com", "");
	public static final ORMLiteUser MOCK_CONTACT_USER = new ORMLiteUser("", "", "dummy@mail.com", "");
	public static final Contact MOCK_CONTACT = new Contact(MOCK_CONTACT_USER, "Default");
	
	private UserList userList = new UserList();
	private MessageList messageList = new MessageList();
	
	public MockDatabaseSystem(){
		userList.add(MOCK_ACTIVE_USER);
	}

	@Override
	public void createConnection(String db, String user, String pass)
			throws SQLException {

	}

	@Override
	public void createTables() throws SQLException {

	}

	@Override
	public void closeConnection() throws SQLException {
		userList.clear();
	}

	@Override
	public IUser getUserByEmail(String email) throws SQLException {
		return userList.get(0);
	}

	@Override
	public UserList getUserList() throws SQLException {
		return userList;
	}

	@Override
	public ContactList getContactList(IUser user) throws SQLException {
		return new ContactList();
	}

	@Override
	public void createUser(String firstName, String lastName, String email, String password) throws SQLException {
		userList.add(new ORMLiteUser(firstName, lastName, email, PasswordEncrypter.encrypt(password)));
		
	}

	@Override
	public void updateUser(IUser user, String firstName, String lastName,
			String email, String password, boolean active) throws SQLException {
		Iterator<IUser> it = userList.iterator();
		while (it.hasNext()){
			IUser dbUser = it.next();
			if (dbUser.getEmail().equals(user.getEmail())){

			}
		}

	}

	@Override
	public void deleteUser(IUser user) throws SQLException {

	}

	@Override
	public UserList getUserList(String term) throws SQLException {
		return userList;
	}

	@Override
	public void createContact(IUser user, Contact contact) throws SQLException {
		
	}

	@Override
	public boolean checkPassword(IUser user, String password)
			throws SQLException {
		return true;
	}

	@Override
	public void updateTag(IUser user, Contact contact) throws SQLException {
		
	}

	@Override
	public UserList getUsersWithContact(IUser user) throws SQLException {
		return userList;
	}

	@Override
	public void addLogMessage(Message message) throws SQLException {
		
	}

	@Override
	public void removeContact(IUser currentUser, IUser contact)
			throws SQLException {
		
	}

	@Override
	public MessageList getLogMessages(IUser from, IUser to, Date start, Date stop)
			throws SQLException {
		return messageList;
	}

	@Override
	public MessageList getOfflineMessages(IUser user) throws SQLException{
		return messageList;
	}
	
}
